package cn.webdai.job.schedule;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 戴金华
 * @date 2020-01-02 9:27
 */
@Component
public class ScheduleTask {

    private Logger logger = LoggerFactory.getLogger(ScheduleTask.class);

    private Integer count = 0;

    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd:hh:mm:ss");
    /**
     * 每三秒执行一次
     */
    @Scheduled(cron = "0/3 * * * * ? ")
    public void process(){
        logger.info(Thread.currentThread().getName()+"的定时任务开始"+(count++));
    }

    @Scheduled(fixedRate = 3000)
    public void reportCurrentTime(){
        logger.info("当前的时间是"+sdf.format(new Date()));
    }
}
